package org.laowenchao.client;

import org.laowenchao.client.rpc.ArticleService;
import org.laowenchao.client.rpc.ArticleServiceAsync;

import com.extjs.gxt.ui.client.widget.form.HtmlEditor;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;

public class NewArticle implements EntryPoint {

	TextBox title = new TextBox();
	HtmlEditor richText = new HtmlEditor();
	Button submit = new Button("submit");
	ArticleServiceAsync blogService = GWT.create(ArticleService.class);
	
	@Override
	public void onModuleLoad() {
		submit.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub
				((ServiceDefTarget)blogService).setServiceEntryPoint("/ArticleService");
				blogService.addArticle(title.getText(), richText.getValue(), new AsyncCallback<Void>(){
					
					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						Window.alert(caught.getMessage());
					}


					@Override
					public void onSuccess(Void result) {
						// TODO Auto-generated method stub
						Window.alert("添加成功");
					}});
				
			}});
		
		RootPanel.get().add(title);
		RootPanel.get().add(richText);
		RootPanel.get().add(submit);
		
	}


}
